<?php

namespace App\Http\Controllers\UserApi;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\IntegralPlan;
use App\Models\SystemImages;
use App\Http\Requests\UserApi\IntegralPlanRequest;

class IntegralPlanController extends BaseController
{
    public function intgral_plan_list(IntegralPlan $integralPlan){
        $data = $integralPlan->orderBy('id','desc')->paginate(15)->toArray();
        if(count($data['data']) > 0){
            foreach ($data['data'] as $k =>$v){
                $data['data'][$k]['all_time'] = $v['valid_day'];
            }
        }
        return self::success($data);
    }

    public function intgral_plan_info(IntegralPlan $integralPlan,IntegralPlanRequest $integralPlanRequest){
        $data = $integralPlan->where('id',$integralPlanRequest->integral_plan_id)->first();
        if(!empty($data)){
            $data->all_time  = $data->valid_day;
        }
        return self::success($data);
    }

    public function intgral_cove(SystemImages $systemImages){
        $url = $systemImages->where('type',1)->first();
        return self::success($url);
    }

    public function company_intgral_cove(SystemImages $systemImages){
        $url = $systemImages->where('type',2)->first();
        return self::success($url);
    }

    public function cash_cove(SystemImages $systemImages){
        $url = $systemImages->where('type',4)->first();
        return self::success($url);
    }
}
